#pragma once
#ifndef ACCEPTOR_H
#define ACCEPTOR_H
#include "NonCopyable.h"
#include "Socket.h"
#include "Channel.h"
namespace mymuduo {

class EventLoop;
class InetAddress;

// 运行在 mainloop 里面的
class Acceptor : NonCopyable {
public:
    using NewConnectionCallback = std::function<void(int socketfd, const InetAddress&)>;
    Acceptor(EventLoop *loop, const InetAddress &listenningAddr, bool reuseport);
    ~Acceptor();
    
    void setNewConnectionCallback(const NewConnectionCallback& cb) { newConnectionCallback_ = cb; }
    bool listenning() const {return listenning_;}
    void listen();

private:

    void handleRead();
    EventLoop* loop_; // Acceptor 用的是用户定义的那个 baseloop
    Socket acceptSocket_;
    Channel acceptChannel_;
    NewConnectionCallback newConnectionCallback_;
    bool listenning_;
};

}

#endif